import UnityEngine

class Health (MonoBehaviour): 
    public maxHealth as int = 10
    health as int
    triggerdead = false
    triggertime = 0.0
    triggercomplete = false
    
    def Start ():
        health = maxHealth
    
    def Update ():
        if Network.isServer:
            if health < 0:
                transform.eulerAngles.z = 30
                triggerdead = true
    
            if triggerdead and not triggercomplete:
                SendMessage("OnDeath")
                Invoke("NetDestroy", 1.0)
                triggercomplete = true
    
    def NetDestroy():
        Network.Destroy(gameObject)
    
    public def Damage(dmg as single):
        health -= dmg
    
    def OnSerializeNetworkView(stream as BitStream, info as NetworkMessageInfo):
        h as int = 0
        if stream.isWriting:
            h = health
            stream.Serialize(h)
        else:
            stream.Serialize(h)
            health = h
    

